package org.lg.dao.impl;

import org.lg.config.Repository;
import org.lg.config.Resource;
import org.lg.dao.CourseDao;
import org.lg.entity.Course;
import org.lg.entity.CourseExample;
import org.lg.mapper.CourseMapper;
import org.lg.page.PageInfo;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Repository("courseDao")
public class CourseDaoImpl implements CourseDao {
    @Resource
    CourseMapper courseMapper;
    @Override
    public List<Course> getAllCourses() throws Exception {
//        List<Course> courses = Arrays.asList(
//        new Course[]{new Course("0089","男"),new Course("0049","女"),new Course("0087","男")});

        return courseMapper.selectByExample(null);
    }

    /**
     * 分页查询学生
     * @param pageInfo
     * @return
     */

    public List<Course> getCourseByPage(PageInfo pageInfo){
        long l = courseMapper.countByExample(null);
        pageInfo.setItemCount((int)l);
        Map<String,Object> map = new HashMap<String,Object>();
        map.put("currPage",pageInfo.getCurrPage());
        map.put("pageSize",pageInfo.getPageSize());
        System.out.println("lllllllllllllllllll");
        return courseMapper.getCourseByPage(map);
    }

    @Override
    public Course getCourseByCno(String cno) throws Exception {
        return courseMapper.selectByPrimaryKey(cno);
    }

    @Override
    public Integer addCourse(Course course) throws Exception {
        return courseMapper.insertSelective(course);
    }

    @Override
    public Integer eidtCourse(Course course) throws Exception {
        return courseMapper.updateByPrimaryKeySelective(course);
    }


}
